import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

/**
 * @author CoderXshuai
 * @date 2021/9/2 21:45
 */
public class TheLargestGeneration {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String[] s = reader.readLine().split(" ");
        int num = Integer.parseInt(s[0]);
        int parent = Integer.parseInt(s[1]);
        Map<String, List<String>> map = new HashMap<>((int) Math.ceil(num / 0.75) + 1);
        for (int i = 0; i < parent; i++) {
            s = reader.readLine().split(" ", 3);
            List<String> list = Arrays.asList(s[2].split(" "));
            map.put(s[0], list);
        }
        Queue<String> q = new LinkedList<>();
        q.add("01");
        int population = 1;
        int max = 0;
        int depth = 1;
        while (!q.isEmpty()) {
            int sz = q.size();
            int temp = 0;
            for (int i = 0; i < sz; i++) {
                String key = q.poll();
                List<String> values = map.getOrDefault(key, null);
                if (values != null) {
                    for (String child : values) {
                        q.offer(child);
                        temp++;
                    }
                }
            }
            depth++;
            if (temp > population) {
                population = temp;
                max = depth;
            }
        }
        System.out.print(population + " " + max);
        reader.close();
    }
}
